/*
 * virtualdevicetestrunner.h
 *
 *  Created on: 10/01/2012
 *      Author: rbender
 */

#ifndef VIRTUALDEVICETESTRUNNER_H_
#define VIRTUALDEVICETESTRUNNER_H_

#include "virtualdevicetestcase.h"
#include <list>
#include <cassert>
#include <iostream>
#include <string>

namespace xvd
{

#define XVD_ASSERT_EQUAL(a, b) assert(a == b) 


    class VirtualDeviceTestRunner
    {
        public:
            const std::string m_runnername;
            VirtualDeviceTestRunner() : m_runnername("MainTest") {}
            VirtualDeviceTestRunner(const std::string& runnername) : m_runnername(runnername) {}

            void Add(VirtualDeviceTestRunner* runner)
            {
                m_runners.push_back(runner);
            }
            void Add(VirtualDeviceTestCase* testcase)
            {
                m_testcases.push_back(testcase);
            }
            void Run()
            {
                std::cout << m_runnername << "..." << std::endl;

                for(std::list<VirtualDeviceTestCase*>::iterator it = m_testcases.begin();
                        it != m_testcases.end(); ++it)
                {
                    std::cout << "  Running Test '" << (*it)->m_testname << "': " << std::flush;
                    this->Prepare();
                    std::cout << "Prepared! " << std::flush;
                    (*it)->Test(this);
                    std::cout << "Tested! " << std::flush;
                    this->Terminate();
                    std::cout << "Terminated! " << std::endl;
                }


                for(std::list<VirtualDeviceTestRunner*>::iterator it = m_runners.begin();
                        it != m_runners.end(); ++it)
                {
                    (*it)->Run();
                }
            }
            virtual void Prepare()
            {

            }
            virtual void Terminate()
            {
            }
			virtual ~VirtualDeviceTestRunner()
			{
				for(std::list<VirtualDeviceTestCase*>::iterator it = m_testcases.begin(); 
						it != m_testcases.end(); ++it)
					delete *it;
			}
        private:
            std::list<VirtualDeviceTestRunner*> m_runners;
            std::list<VirtualDeviceTestCase*> m_testcases;
    };
}

#endif /* VIRTUALDEVICETESTRUNNER_H_ */
